package src;

import javax.swing.*;
import java.awt.*;

public class TransactionDeleteDialog extends JDialog {
    private JTextField transactionIdField;
    private boolean confirmed = false;

    public TransactionDeleteDialog(Frame owner) {
        super(owner, "删除交易记录", true);
        setSize(400, 200);
        setLocationRelativeTo(owner);

        // 创建主面板
        JPanel mainPanel = new JPanel(new BorderLayout());
        mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

        // 创建输入面板
        JPanel inputPanel = new JPanel(new GridLayout(1, 2, 10, 10));
        inputPanel.add(new JLabel("交易流水号:"));
        transactionIdField = new JTextField();
        inputPanel.add(transactionIdField);

        // 创建按钮面板
        JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 10));
        JButton confirmButton = new JButton("确认");
        JButton cancelButton = new JButton("取消");

        // 添加事件监听器
        confirmButton.addActionListener(e -> {
            if (validateInput()) {
                confirmed = true;
                dispose();
            }
        });
        cancelButton.addActionListener(e -> dispose());

        buttonPanel.add(confirmButton);
        buttonPanel.add(cancelButton);

        // 添加组件到主面板
        mainPanel.add(inputPanel, BorderLayout.CENTER);
        mainPanel.add(buttonPanel, BorderLayout.SOUTH);

        add(mainPanel);
    }

    private boolean validateInput() {
        String transactionId = transactionIdField.getText().trim();
        if (transactionId.isEmpty()) {
            JOptionPane.showMessageDialog(this,
                "请输入交易流水号",
                "输入错误",
                JOptionPane.ERROR_MESSAGE);
            return false;
        }
        return true;
    }

    public String getTransactionId() {
        return transactionIdField.getText().trim();
    }

    public boolean isConfirmed() {
        return confirmed;
    }
} 